﻿/*
	Copyright (c) 2013 Andrew Meyer

	Permission is hereby granted, free of charge, to any person obtaining a copy of this software
	and associated documentation files (the "Software"), to deal in the Software without
	restriction, including without limitation the right to use, copy, modify, merge, publish,
	distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
	Software is furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in all copies or
	substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
	BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
	NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
	DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

using System.Windows.Media;
using System.Windows.Media.Media3D;

namespace Ascend
{
	/// <summary>
	/// An Ascend.SceneNode that contains a System.Windows.Media.Media3D.Light. This class cannot be
	/// inherited.
	/// </summary>
	public sealed class LightSceneNode : SceneNode
	{
		#region Lifecycle
		internal LightSceneNode()
		{
			// Create default light content
			Data.Children.Add(DEFAULT_LIGHT);
		}

		/// <summary>
		/// Creates a new instance of the Ascend.LightSceneNode class.
		/// </summary>
		public static LightSceneNode Create()
		{
			return new LightSceneNode();
		}

		/// <summary>
		/// Creates a new instance of the Ascend.LightSceneNode class with given light content.
		/// </summary>
		/// <param name="light">
		/// The light content for the Ascend.LightSceneNode.
		/// </param>
		public static LightSceneNode Create(Light light)
		{
			return new LightSceneNode
			{
				Light = light
			};
		}
		#endregion

		#region Constants
		private readonly Light DEFAULT_LIGHT = new AmbientLight(Colors.Black);
		#endregion

		#region Public Properties
		private Light _light;
		/// <summary>
		/// Gets or sets the light content of this Ascend.LightSceneNode.
		/// </summary>
		public Light Light
		{
			get
			{
				return _light;
			}
			
			set
			{
				if (_light == value)
				{
					return;
				}

				_light = value;

				Data.Children[1] = (_light != null)
					? _light
					: DEFAULT_LIGHT;
			}
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Creates a deep copy of this Ascend.LightSceneNode, including deep copies of all
		/// children.
		/// </summary>
		/// <returns>
		/// Returns the deep copy.
		/// </returns>
		public override TransformableObject Clone()
		{
			LightSceneNode clone = new LightSceneNode();

			clone.Light = (Light != null)
				? Light.Clone()
				: null;

			CloneProperties(clone);
			CloneChildren(clone);

			return clone;
		}
		#endregion
	}
}
